package zero.tech.games.gate.topic;

import java.util.List;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.ZeroContext;
import zero.tech.core.data.Resp;
import zero.tech.games.common.ClubMemberUtil;
import zero.tech.games.common.Code;
import zero.tech.games.common.TopicOrder;
import zero.tech.games.common.topic.ClubMemberChange;
import zero.tech.games.entity.games.ClubMember;
import zero.tech.games.gate.data.GATECMD;
import zero.tech.games.gate.util.PackageUtil;
import zero.tech.redis.topic.TopicChannelType;
import zero.tech.redis.topic.TopicProcess;
import zero.tech.wsnet.controller.CacheOnline;
import zero.tech.wsnet.controller.Controller;
import zero.tech.wsnet.data.Message;

public class ClubMemberChangeTopic extends TopicProcess{

	@Override
	public String orderType() {
		return TopicOrder.ACCOUNT_CHANGE;
	}

	@Override
	public void process(String message) throws Exception {
		ClubMemberChange clubMemberChange=JSONObject.parseObject(message,ClubMemberChange.class);
		int club_id=clubMemberChange.getClub_id();
		List<Integer> list=clubMemberChange.getUids();
		if(!list.isEmpty()) {
			ClubMemberUtil clubMemberUtil =  ZeroContext.getInstance(ClubMemberUtil.class);
			for(Integer uid:list) {
				Controller controller=CacheOnline.getCache().getOnlines().get(uid);
				if(controller!=null&&controller.getWebClient()!=null&&controller.getWebClient().isAlive()) {
					ClubMember clubMember=clubMemberUtil.getClubMember(club_id, uid);
					controller.getWebClient().sendMessage(Message.build(GATECMD.NOTIFY_ACCOUNT_CHANGE, Resp.build(Code.OK, "账户改变",PackageUtil.packageNotifyClubMemberChange(clubMember))));
				}
			}
		}
	}

	@Override
	public TopicChannelType channelType() {
		return TopicChannelType.CLUB_MEMBER_CHANGE;
	}

}
